Completed
Push — master ( e3ee1d...5cbb1b )
by Justin
01:36
created

  A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 52
rs 9.4929

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var assert = require('chai').assert,
2
    GedcomX = require('../../');
3
4
describe('DisplayProperties', function(){
5
  
6
  it('Create plain', function(){
7
    assert.instanceOf(new GedcomX.DisplayProperties(), GedcomX.DisplayProperties, 'An instance of DisplayProperties is not returned when calling the constructor with new.');
8
    assert.instanceOf(GedcomX.DisplayProperties(), GedcomX.DisplayProperties, 'An instance of DisplayProperties is not returned when calling the constructor without new.');
9
  });
10
  
11
  it('Create with JSON', function(){
12
    var display = GedcomX.DisplayProperties({
13
      "name" : "Joe",
14
      "gender" : "Male",
15
      "lifespan" : "1900-1956",
16
      "birthDate" : "3 March 1900",
17
      "birthPlace" : "A place",
18
      "deathDate" : "14 January 1956",
19
      "deathPlace" : "Another place",
20
      "marriageDate" : "9 August 1927",
21
      "marriagePlace" : "Marriage place",
22
      "ascendancyNumber" : "3",
23
      "descendancyNumber" : "6",
24
      "familiesAsParent" : [{
25
        "parent1" :  {
26
          "resource" : "#parent1"
27
        },
28
        "parent2" :  {
29
          "resource" : "#parent2"
30
        },
31
        "children" : [ 
32
          { "resource" : "#child1" }, 
33
          { "resource" : "#child2" } 
34
        ]
35
      }],
36
      "familiesAsChild" : [{
37
        "parent1" :  {
38
          "resource" : "#parent1"
39
        },
40
        "parent2" :  {
41
          "resource" : "#parent2"
42
        },
43
        "children" : [ 
44
          { "resource" : "#child1" }, 
45
          { "resource" : "#child2" } 
46
        ]
47
      }]
48
    });
49
    assert.equal(display.getName(), 'Joe');
50
    assert.equal(display.getGender(), 'Male');
51
    assert.equal(display.getLifespan(), '1900-1956');
52
    assert.equal(display.getBirthDate(), '3 March 1900');
53
    assert.equal(display.getBirthPlace(), 'A place');
54
    assert.equal(display.getDeathDate(), '14 January 1956');
55
    assert.equal(display.getDeathPlace(), 'Another place');
56
    assert.equal(display.getMarriageDate(), '9 August 1927');
57
    assert.equal(display.getMarriagePlace(), 'Marriage place');
58
    assert.equal(display.getAscendancyNumber(), '3');
59
    assert.equal(display.getDescendancyNumber(), '6');
60
    assert.equal(display.getFamiliesAsParent().length, 1);
61
    assert.equal(display.getFamiliesAsChild().length, 1);
62
  });
63
  
64
  it('Build', function(){
65
    var display = GedcomX.DisplayProperties()
66
      .setName('Joe')
67
      .setGender('Male')
68
      .setLifespan('1900-1956')
69
      .setBirthDate('3 March 1900')
70
      .setBirthPlace('A place')
71
      .setDeathDate('14 January 1956')
72
      .setDeathPlace('Another place')
73
      .setMarriageDate('9 August 1927')
74
      .setMarriagePlace('Marriage place')
75
      .setAscendancyNumber('3')
76
      .setDescendancyNumber('6')
77
      .addFamilyAsParent({
78
        "parent1" :  {
79
          "resource" : "#parent1"
80
        },
81
        "parent2" :  {
82
          "resource" : "#parent2"
83
        },
84
        "children" : [ 
85
          { "resource" : "#child1" }, 
86
          { "resource" : "#child2" } 
87
        ]
88
      })
89
      .addFamilyAsChild({
90
        "parent1" :  {
91
          "resource" : "#parent1"
92
        },
93
        "parent2" :  {
94
          "resource" : "#parent2"
95
        },
96
        "children" : [ 
97
          { "resource" : "#child1" }, 
98
          { "resource" : "#child2" } 
99
        ]
100
      });
101
    assert.equal(display.getName(), 'Joe');
102
    assert.equal(display.getGender(), 'Male');
103
    assert.equal(display.getLifespan(), '1900-1956');
104
    assert.equal(display.getBirthDate(), '3 March 1900');
105
    assert.equal(display.getBirthPlace(), 'A place');
106
    assert.equal(display.getDeathDate(), '14 January 1956');
107
    assert.equal(display.getDeathPlace(), 'Another place');
108
    assert.equal(display.getMarriageDate(), '9 August 1927');
109
    assert.equal(display.getMarriagePlace(), 'Marriage place');
110
    assert.equal(display.getAscendancyNumber(), '3');
111
    assert.equal(display.getDescendancyNumber(), '6');
112
    assert.equal(display.getFamiliesAsParent().length, 1);
113
    assert.equal(display.getFamiliesAsChild().length, 1);
114
  });
115
  
116
  it('toJSON', function(){
117
    var data = {
118
      "name" : "Joe",
119
      "gender" : "Male",
120
      "lifespan" : "1900-1956",
121
      "birthDate" : "3 March 1900",
122
      "birthPlace" : "A place",
123
      "deathDate" : "14 January 1956",
124
      "deathPlace" : "Another place",
125
      "marriageDate" : "9 August 1927",
126
      "marriagePlace" : "Marriage place",
127
      "ascendancyNumber" : "3",
128
      "descendancyNumber" : "6",
129
      "familiesAsParent" : [{
130
        "parent1" :  {
131
          "resource" : "#parent1"
132
        },
133
        "parent2" :  {
134
          "resource" : "#parent2"
135
        },
136
        "children" : [ 
137
          { "resource" : "#child1" }, 
138
          { "resource" : "#child2" } 
139
        ]
140
      }],
141
      "familiesAsChild" : [{
142
        "parent1" :  {
143
          "resource" : "#parent1"
144
        },
145
        "parent2" :  {
146
          "resource" : "#parent2"
147
        },
148
        "children" : [ 
149
          { "resource" : "#child1" }, 
150
          { "resource" : "#child2" } 
151
        ]
152
      }]
153
    }, display = GedcomX.DisplayProperties(data);
154
    assert.deepEqual(display.toJSON(), data);
155
  });
156
  
157
  it('constructor does not copy instances', function(){
158
    var obj1 = GedcomX.DisplayProperties();
159
    var obj2 = GedcomX.DisplayProperties(obj1);
160
    assert.strictEqual(obj1, obj2);
161
  });
162
  
163
});